/*
* ============================================================================
*  Name     : GV60ListView.cpp
*  Part of  : GV60
*  Copyright: Wipo Software
* ============================================================================
*/

// INCLUDE FILES
#include  <aknviewappui.h>
#include  <aknlists.h>
#include  <avkon.hrh>
#include  <GV60.rsg>
#include  "GV60.hrh"
#include  "GV60AppUi.h"
#include  "GV60PhonebookView.h"
#include  "GV60PhonebookContainer.h"


// ================= MEMBER FUNCTIONS =======================

void CGV60PhonebookView::ConstructL()
{
  BaseConstructL( R_GV60_PHONEBOOK_VIEW );
  
  m_pContainer = NULL;
}

CGV60PhonebookView::~CGV60PhonebookView()
{
  if (m_pContainer)
  {
    AppUi()->RemoveFromViewStack( *this, m_pContainer );

    delete m_pContainer;
    m_pContainer = NULL;
  }
}

TUid CGV60PhonebookView::Id() const
{
  return KGV60PhonebookViewId;
}

void CGV60PhonebookView::SizeChanged()
{
  if (m_pContainer)
  {
    m_pContainer->SetRect(ClientRect());
  }
}

void CGV60PhonebookView::HandleCommandL(TInt aCommand)
{   
  switch ( aCommand )
  {
    case EAknSoftkeyBack:
      AppUi()->HandleCommandL(EEikCmdExit);
      break;

    default:
      AppUi()->HandleCommandL( aCommand );
      break;
  }
}

void CGV60PhonebookView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* /*aMenuPane*/)
{
  if (aResourceId == R_GV60_MENUBAR_PHONEBOOK_VIEW_MENU)
  {
  }
}

void CGV60PhonebookView::HandleClientRectChange()
{
  if (m_pContainer)
  {
    m_pContainer->SetRect(ClientRect());
  }
}

void CGV60PhonebookView::DoActivateL(const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
{
  // Create the container the first time that the view is activated
  if (!m_pContainer)
  {
    m_pContainer = new (ELeave) CGV60PhonebookContainer(this);
    m_pContainer->SetMopParent(this);
    m_pContainer->ConstructL( ClientRect() );
    AppUi()->AddToStackL(*this, m_pContainer);
  }
}

void CGV60PhonebookView::DoDeactivate()
{
  // Nothing to do... we mantain the container, so the list
  // is not destroyed
}

void CGV60PhonebookView::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
{
  User::LeaveIfNull(m_pContainer);

  switch(aEventType)
  {
    case EEventEnterKeyPressed:
    case EEventItemDoubleClicked:
      AppUi()->HandleCommandL(EGV60CmdDialContact);
      break;
    default:
      break;
  }
}

TInt CGV60PhonebookView::GetSelectedItem()
{
  if (m_pContainer)
  {
    return m_pContainer->GetSelectedItem();
  }
  return -1;
}

// End of File

